use core::arch::asm;

#[inline(always)]
pub(crate) fn arch_set_my_processor_id(id: usize) {
    unsafe {
        asm!(
            "msr tpidr_el0, {0}",
            in(reg) id
        );
    }
}

#[inline(always)]
pub(crate) fn arch_my_processor_id() -> usize {
    let id;
    unsafe {
        asm!(
            "mrs {0}, tpidr_el1",
            out(reg) id
        );
    }
    id
}

#[inline(always)]
pub(crate) fn arch_cpu_relax() {
    unsafe {
        core::arch::aarch64::__yield();
    }
}

#[inline(always)]
pub(crate) fn arch_smp_mb_acquire() {
    unsafe {
        core::arch::aarch64::__dmb(core::arch::aarch64::ISHLD);
    }
}

#[inline(always)]
pub(crate) fn arch_smp_mb_release() {
    unsafe {
        core::arch::aarch64::__dmb(core::arch::aarch64::ISHST);
    }
}

#[inline(always)]
pub(crate) fn arch_smp_mb() {
    unsafe {
        core::arch::aarch64::__dmb(core::arch::aarch64::ISH);
    }
}

#[inline(always)]
pub(crate) fn arch_isb() {
    unsafe {
        core::arch::aarch64::__isb(core::arch::aarch64::SY);
    }
}
